<html>
<head>
<title>Shutdown</title>
<!--
	(C) Ruslan Mikhaylenko mirusnet@gmail.com 2013
	Simple gadget to shutdown the computer after 15,25,30,35,40,45,50,55,60 minutes
--> 

<style type="text/css">
body { margin: 0; margin-bottom: 0; width: 330px; height: 24px; background-color: black; }
</style>

</head>
<script language="Javascript">
	var button = [false, false, false, false, false, false, false, false];
	var timeout_id;
	var timeout_set = false;
	
	function shutdown() {
		System.Shell.execute('shutdown', '-s -t 120');  
	}

	function timeout_init(position) {
		//Cancel the timer if already running
		if((button[position] == true) && (timeout_set == true)) {
			button[position] = false;
			//System.Shell.execute('shutdown', '-a');
			clearTimeout(timeout_id);
			timeout_set = false;
			return;
		}
		
		//Clear previously pressed button
		for(var j=0; j<=9; j++) {
			var image_off = "src/" + j + "-off.png"
			document.getElementById(j).src = image_off;
			button[j] = false;
			}
		
		if(timeout_set != false) {
			System.Shell.execute('shutdown', '-a');
			clearTimeout(timeout_id);
			}
		
		button[position] = true;
		var image_on = "src/" + position + "-on.png"
		document.getElementById(position).src = image_on;
		timeout_set = true;
		var miliseconds = (position+3)*5*60*1000;
		timeout_id = setTimeout('shutdown()', miliseconds);
	}

	function mouse_out(position) {
		var image_on = "src/" + position + "-on.png"
		var image_off = "src/" + position + "-off.png"
		if(button[position] == true) document.getElementById(position).src = image_on;
		else document.getElementById(position).src = image_off;
	}

</script>
<body>
<g:background src="src/background.png" style="position:absolute;top:0;left:0;" opacity="0">

<script language="Javascript">
	document.write('<table><tr>');
	for(var i=0; i<=button.length+1; i++)
		document.write('<td><img src="src/'+i+'-off.png" onmouseover="this.src=\'src/'+i+'-on.png\';" onmouseout="mouse_out('+i+')" onClick="timeout_init('+i+')" id="'+i+'"/></td>');
	document.write('</table></tr>');
</script>
 
</body>
</html>